package com.allwees.bs.c.module.user.listener;

import com.allwees.bs.c.module.security.JwtTokenHelper;
import com.allwees.bs.c.module.user.event.InvalidateTokenEvent;
import com.allwees.bs.core.model.user.context.CurrentUser;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

import javax.annotation.Resource;

/**
 * @author Daniel
 * @version 1.0.0
 * @since 2020/11/30 14:32
 */
@Component
public class InvalidateTokenListener {

    @Resource
    private JwtTokenHelper jwtTokenHelper;

    @TransactionalEventListener
    public void onEvent(InvalidateTokenEvent event) {
        jwtTokenHelper.invalidateToken((CurrentUser)event.getSource());
    }
}
